package cn.diancan.service.impl;

import java.lang.reflect.InvocationTargetException;

import javax.annotation.Resource;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

import cn.diancan.dao.MyBaseDao;
import cn.diancan.model.ShopCustomer;
import cn.diancan.model.SysDataLog;
import cn.diancan.service.SysDataLogServie;

@Component("sysDataLogServie")
public class SysDataLogServieImpl implements SysDataLogServie{
    
    
    @Resource(name="MyBaseDao")
    private MyBaseDao<SysDataLog> sysDataLogDao;
    public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
	String m ="";
	System.out.println(HashCodeBuilder.reflectionHashCode(m.getClass().getName()));
	ShopCustomer shopCustomer =new ShopCustomer();
	shopCustomer.init();
	shopCustomer.setCustomerSex(0);
	
	ShopCustomer shopCustomer2 = new ShopCustomer();
	BeanUtils.copyProperties(shopCustomer2, shopCustomer);
	//ShopCustomer shopCustomer2 =shopCustomer;
	shopCustomer2.setCustomerSex(1);
	System.out.println(shopCustomer.hashCode());
	System.out.println(shopCustomer2.hashCode());
    }
    

    @Override
    public boolean saveSysDataLog(String dataStamp, Object sourceData, Object modifyData) {
	SysDataLog log = new SysDataLog();
	log.init();
	
	log.setDataType(HashCodeBuilder.reflectionHashCode(sourceData.getClass().getName()+modifyData.getClass().getName()));
	log.setDataStamp(dataStamp);
	log.setSourceClass(sourceData.getClass().getName());
	log.setSourceData(JSON.toJSONString(sourceData));
	log.setModifyClass(modifyData.getClass().getName());
	log.setModifyData(JSON.toJSONString(modifyData));
	
	sysDataLogDao.save(log);
	return true;
    }
    
    

}
